import pytest
from common.driver_factory import DriverFactory


@pytest.fixture(scope="class")
def driver():
    df = DriverFactory()
    page = df.get_page()
    yield page
    df.quit()


def pytest_make_parametrize_id(config, val):
    # 如果值是中文字符串，直接返回中文而不是 Unicode
    if isinstance(val, dict) and "case_name" in val:
        try:
            return val["case_name"]
        except KeyError:
            pass
    if isinstance(val, str):
        try:
            val.encode("utf-8")  # 如果能编码说明是正常字符串
            return val
        except:
            pass
    return None  # 默认方式处理
